package edu.pdx.LAMA.AndroidCourse.scheduler;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class EventDetailsActivity extends ActionBarActivity {
	

	private static final String TAG = "EventDetailsActivity";
	public static final String EXTRA_BUNDLE = "edu.pdx.LAMA.AndroidCourse.scheduler";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event_details);
		
		Log.d(TAG, "Does this activity even get created");
		
		FragmentManager fm = getSupportFragmentManager();
		Fragment fragment = fm.findFragmentById(R.id.fragmentContainer2);
		
		int index = (Integer) getIntent().getSerializableExtra(EventDetailsFragment.EXTRA_EVENT_SELECTED);
		String date = (String) getIntent().getStringExtra(EventDetailsFragment.EXTRA_EVENT_DATE_SELECTED);
		Log.d(TAG, "The value of index here is "+index);
		//ArrayList<EventDetails> eDetails= (ArrayList<EventDetails>) getIntent().getSerializableExtra(EventDetailsFragment.EXTRA_ALL_EVENTS_FOR_DAY);
		
		if (fragment == null){
			Log.d(TAG, "Does it even come here?");
			fragment = EventDetailsFragment.newInstance(index,date,this);
			//fragment = new EventDetailsFragment();
			fm.beginTransaction().add(R.id.fragmentContainer2, fragment).commit();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.event_details, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
